// cache 控制

export default {
  setCache: (key, value) => {
    localStorage.setItem(key, JSON.stringify({data: value, time: new Date().getTime()}))
  },
  // this.$plugins.cacheControl.getCache('alls').then((res) => {
  //   this.alls = res.data
  // }).catch((err) => {
  //   this.findStrageryByNetwork() // 数据过期从网络获取
  // })
  getCache: (key, deadline = 5) => {
    return new Promise((resolve, reject) => {
      let cache = JSON.parse(localStorage.getItem(key))
      if (!cache) reject('不存在该缓存')
      if (new Date().getTime() - cache.time > deadline * 1000 * 60) reject('缓存过期')
      resolve(cache)
    })
  }
}